package cn.hl.hm.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.google.common.collect.Lists;
import com.vizhuo.app.constant.AppVersionConstant;
import com.vizhuo.client.base.AbstractVo;
import com.vizhuo.client.business.appmanage.constant.AppPushConstant;
import com.vizhuo.client.business.appmanage.vo.AndroidPushCustomMessage;
import com.vizhuo.client.business.appmanage.vo.AppVersionVo;
import com.vizhuo.client.business.appmanage.vo.IOSPushCustomMessage;
import com.vizhuo.client.business.match.goods.vo.BoundsVo;
import com.vizhuo.client.business.match.goods.vo.GoodsVo;
import com.vizhuo.client.business.meb.mebacc.vo.MebConsignerVo;
import com.vizhuo.client.business.meb.mebacc.vo.MebDriverVo;
import com.vizhuo.client.business.meb.mebacc.vo.MebInfoVo;
import com.vizhuo.push.umeng.base.PushClient;
import com.vizhuo.push.umeng.base.PushConstant;
import com.vizhuo.utils.ArrayUtil;
import com.vizhuo.utils.DataUtil;
import com.vizhuo.utils.PropertiesUtil;
import com.vizhuo.utils.StringUtil;
import com.vizhuo.utils.match.MatchUtil;
import com.vizhuo.utils.term.TermsCode;

import cn.hl.hm.entity.AppDevice;
import cn.hl.hm.entity.HelpInfo;
import cn.hl.hm.service.AppPushToDriverService;

/**
 * 推送至 司机客户端 服务实现类
 * 
 * @author dcq 作者 E-mail: ding_chuanqin@163.com
 * @date 创建时间：2016年7月1日 下午3:10:39
 * @version 1.0
 * @parameter
 * @since
 * @return
 */
@Service("appPushToDriverService_umeng")
public class AppPushToDriverServiceImpl extends UmengAppPushServiceImpl implements AppPushToDriverService {
    private static Logger logger = LoggerFactory.getLogger(AppPushToDriverServiceImpl.class);

    @Autowired
    @Qualifier("logisticsinfoPushAndroidClient")
    private PushClient logisticsinfoPushAndroidClient;

    @Autowired
    @Qualifier("driverPushAndroidClient")
    private PushClient driverPushAndroidClient;

    @Autowired
    @Qualifier("consignerPushAndroidClient")
    private PushClient consignerPushAndroidClient;

    @Autowired
    @Qualifier("driverPushIOSClient")
    private PushClient driverPushIOSClient;

    @Autowired
    @Qualifier("logisticsinfoPushIOSClient")
    private PushClient logisticsinfoPushIOSClient;

//    @Autowired
//    @Qualifier("appDeviceService")
//    private AppDeviceService appDeviceService;
//
//    @Autowired
//    @Qualifier("mebDriverIMapper")
//    private MebDriverIMapper mebDriverIMapper;
//
//    @Autowired
//    @Qualifier("mebAccIMapper")
//    private MebAccIMapper mebAccIMapper;
//
//    @Autowired
//    @Qualifier("appPushTaskMapper")
//    private AppPushTaskMapper appPushTaskMapper;

    @Override
    public void pushForceUpgrade4Android(AppVersionVo appVersionVo) throws Exception {
        logger.info("enter pushForceUpgrade4Android of AppPushToDriverServiceImpl ");
        String localPath = PropertiesUtil.readValue(PropertiesUtil.CONFIG_PATH, PropertiesUtil.CONFIG_LOCALHOST_PATH);
        appVersionVo.setFileURL(localPath + appVersionVo.getFileURL());
        AndroidPushCustomMessage custom = new AndroidPushCustomMessage();
        custom.setType(AppPushConstant.OPERATION_TYPE_FORCE_UPGRADE);
        custom.setAppVersionVo(appVersionVo);
        push2Android(AppPushConstant.OPERATION_TYPE_FORCE_UPGRADE, PushConstant.DISPLAY_TYPE_MESSAGE,
                PushConstant.TYPE_BROADCAST, AppPushConstant.PUSH_UPGRADE_TITLE, "新版本v" + appVersionVo.getVersion()
                        + "点击打开应用进行更新", null, driverPushAndroidClient, custom);
    }

    // 抢单后被指定为承运人
    @Override
    public void pushOrderToDriverOrder(String phoneNumber, GoodsVo goodsVo) throws Exception {
        logger.info("enter pushOrderToDriverOrder of AppPushToDriverServiceImpl ");
        List<String> phoneNumbers = new ArrayList<String>();
        phoneNumbers.add(phoneNumber);
        DataUtil.choosePhoneByOnLine(phoneNumbers);// 剔除不在线的用户
        logger.info("剔除不在线用户后:" + phoneNumbers.toString());
        DataUtil.choosePushSetOn(phoneNumbers, TermsCode.APP_PUSHINSTALL_TYPE_LIST.GOODSREMIND_STATE);// 剔除关掉了推送设置的用户
        logger.info("剔除关掉了推送设置的用户后:" + phoneNumbers.toString());
        if (phoneNumbers == null || phoneNumbers.isEmpty()) {
            return;
        }

        String token = "";//appDeviceService.selectToken(phoneNumber, AppVersionConstant.TYPE_ANDROID_DRIVER);
        int appType = AppVersionConstant.TYPE_ANDROID_DRIVER;
        // String goodInfo = MatchUtil.getGoodsRemark(goodsVo);
        String goodInfo = "订单尾号" + goodsVo.getGoodsNo().substring(goodsVo.getGoodsNo().length() - 6)
                + "指定你来承运，请至订单管理-待评价中查询！";
        if (StringUtil.isEmpty(token)) {
            token = "";//appDeviceService.selectToken(phoneNumber, AppVersionConstant.TYPE_IOS_DRIVER);
            appType = AppVersionConstant.TYPE_IOS_DRIVER;
        }
        if (StringUtil.isEmpty(token)) {
            throw new Exception("司机的手机号" + phoneNumber + "没有找寻到对应的数据，无法开始推送服务");
        }
        if (appType == AppVersionConstant.TYPE_ANDROID_DRIVER) {
            AndroidPushCustomMessage custom = new AndroidPushCustomMessage();
            custom.setType(AppPushConstant.OPERATION_TYPE_TO_DRIVER_ORDER);
            custom.setContext(goodInfo);
            custom.setGoodVo(goodsVo);
            push2Android(AppPushConstant.OPERATION_TYPE_TO_DRIVER_ORDER, PushConstant.DISPLAY_TYPE_MESSAGE,
                    PushConstant.TYPE_UNICAST, AppPushConstant.PUSH_CHOOSE_DRIVER_SUCCESS_TITLE, goodInfo, token,
                    driverPushAndroidClient, custom);
        } else {
            IOSPushCustomMessage customIOS = new IOSPushCustomMessage();
            customIOS.setType(AppPushConstant.OPERATION_TYPE_TO_DRIVER_ORDER);
            customIOS.setContext(goodInfo);
            customIOS.setGoodVo(goodsVo);
            push2IOS(AppPushConstant.OPERATION_TYPE_TO_DRIVER_ORDER, PushConstant.TYPE_UNICAST,
                    AppPushConstant.PUSH_CHOOSE_DRIVER_SUCCESS_TITLE, token, driverPushIOSClient, customIOS);
        }
    }

//    // 指定抢单记录中的某个司机为承运人后推送 消息
//    @Override
//    public void pushChooseDriverInfo(List<MatOrderRob> robs, GoodsVo goodsVo) throws Exception {
//        logger.info("enter pushChooseDriverInfo of AppPushToDriverServiceImpl ");
//        if (StringUtil.isBlank(goodsVo.getGoodsNo())) {
//            goodsVo.setGoodsNo("000000000");
//        }
//        String successDriverToken = null;
//        int successAppType = 0;
//        StringBuilder failBuild2Android = new StringBuilder();
//        StringBuilder failBuild2IOS = new StringBuilder();
//        // String goodInfo = MatchUtil.getGoodsRemark(goodsVo);
//        String goodsendno = goodsVo.getGoodsNo().substring(goodsVo.getGoodsNo().length() - 6);
//        String goodInfo = "订单尾号" + goodsendno + "指定你来承运，请至订单管理-待评价中查询！";
//        for (MatOrderRob rob : robs) {
//            if (MatOrderRobConstant.IS_CARRIER_YES.equals(rob.getIsCarrier())) {
//
//                //
//                List<String> phoneNumbers = new ArrayList<String>();
//                phoneNumbers.add(rob.getRobPhone());
//                DataUtil.choosePhoneByOnLine(phoneNumbers);// 剔除不在线的用户
//                logger.info("剔除不在线用户后:" + phoneNumbers.toString());
//                DataUtil.choosePushSetOn(phoneNumbers, TermsCode.APP_PUSHINSTALL_TYPE_LIST.TOCARRIERREMIND_STATE);// 剔除关掉了推送设置的用户
//                logger.info("剔除关掉了推送设置的用户后:" + phoneNumbers.toString());
//                if (phoneNumbers == null || phoneNumbers.isEmpty()) {
//                    continue;
//                }
//                //
//                successDriverToken = appDeviceService.selectToken(rob.getRobPhone(),
//                        AppVersionConstant.TYPE_ANDROID_DRIVER);
//                if (StringUtil.isEmpty(successDriverToken)) {
//                    successDriverToken = appDeviceService.selectToken(rob.getRobPhone(),
//                            AppVersionConstant.TYPE_IOS_DRIVER);
//                    successAppType = AppVersionConstant.TYPE_IOS_DRIVER;
//                } else {
//                    successAppType = AppVersionConstant.TYPE_ANDROID_DRIVER;
//                }
//            } else {
//
//                //
//                List<String> phoneNumbers = new ArrayList<String>();
//                phoneNumbers.add(rob.getRobPhone());
//                DataUtil.choosePhoneByOnLine(phoneNumbers);// 剔除不在线的用户
//                logger.info("剔除不在线用户后:" + phoneNumbers.toString());
//                DataUtil.choosePushSetOn(phoneNumbers, TermsCode.APP_PUSHINSTALL_TYPE_LIST.NO_TOCARRIERREMIND_STATE);// 剔除关掉了推送设置的用户
//                logger.info("剔除关掉了推送设置的用户后:" + phoneNumbers.toString());
//                if (phoneNumbers == null || phoneNumbers.isEmpty()) {
//                    continue;
//                }
//                //
//                String failDriverToken = appDeviceService.selectToken(rob.getRobPhone(),
//                        AppVersionConstant.TYPE_ANDROID_DRIVER);
//                if (StringUtil.isEmpty(failDriverToken)) {
//                    failDriverToken = appDeviceService.selectToken(rob.getRobPhone(),
//                            AppVersionConstant.TYPE_IOS_DRIVER);
//                    if (StringUtil.isNotBlank(failDriverToken)) {
//                        failBuild2IOS.append("," + failDriverToken);
//                    }
//                } else {
//                    failBuild2Android.append("," + failDriverToken);
//                }
//            }
//        }
//        // 成功只有一个人,单播
//        if (successAppType == AppVersionConstant.TYPE_ANDROID_DRIVER) {
//            AndroidPushCustomMessage custom = new AndroidPushCustomMessage();
//            custom.setType(AppPushConstant.OPERATION_TYPE_CHOOSE_DRIVER);
//            custom.setContext(goodInfo);
//            custom.setGoodVo(goodsVo);
//            push2Android(AppPushConstant.OPERATION_TYPE_CHOOSE_DRIVER, PushConstant.DISPLAY_TYPE_MESSAGE,
//                    PushConstant.TYPE_UNICAST, AppPushConstant.PUSH_CHOOSE_DRIVER_SUCCESS_TITLE, goodInfo,
//                    successDriverToken, driverPushAndroidClient, custom);
//        } else {
//            IOSPushCustomMessage customIOS = new IOSPushCustomMessage();
//            customIOS.setType(AppPushConstant.OPERATION_TYPE_CHOOSE_DRIVER);
//            customIOS.setContext(goodInfo);
//            customIOS.setGoodVo(goodsVo);
//            push2IOS(AppPushConstant.OPERATION_TYPE_CHOOSE_DRIVER, PushConstant.TYPE_UNICAST, goodInfo,
//                    successDriverToken, driverPushIOSClient, customIOS);
//        }
//        // 失败存在多个人,列播
//        if (failBuild2Android.length() > 1) {
//            AndroidPushCustomMessage custom = new AndroidPushCustomMessage();
//            custom.setType(AppPushConstant.OPERATION_TYPE_CHOOSE_DRIVER_FAIL);
//            goodInfo = "订单尾号" + goodsendno + "已成交，尝试抢其他货物吧！";
//            custom.setContext(goodInfo);
//            custom.setGoodVo(goodsVo);
//            String failAndroidToken = failBuild2Android.toString().substring(1);
//            push2Android(AppPushConstant.OPERATION_TYPE_CHOOSE_DRIVER_FAIL, PushConstant.DISPLAY_TYPE_MESSAGE,
//                    PushConstant.TYPE_LISTCAST, AppPushConstant.PUSH_CHOOSE_DRIVER_FAIL_TITLE, goodInfo,
//                    failAndroidToken, driverPushAndroidClient, custom);
//
//        }
//        if (failBuild2IOS.length() > 1) {
//            IOSPushCustomMessage customIOS = new IOSPushCustomMessage();
//            customIOS.setType(AppPushConstant.OPERATION_TYPE_CHOOSE_DRIVER_FAIL);
//            goodInfo = "订单尾号" + goodsendno + "已成交，尝试抢其他货物吧！";
//            customIOS.setContext(goodInfo);
//            customIOS.setGoodVo(goodsVo);
//            String failIOSToken = failBuild2IOS.toString().substring(1);
//            push2IOS(AppPushConstant.OPERATION_TYPE_CHOOSE_DRIVER_FAIL, PushConstant.TYPE_LISTCAST, goodInfo,
//                    failIOSToken, driverPushIOSClient, customIOS);
//        }
//        logger.info("left pushChooseDriverInfo of AppPushToDriverServiceImpl ");
//
//    }
    

    /**
     * 承运人评价发货方
     * 
     * @param targetPhoneNumber
     *            发货方手机号
     * @param valuatorName
     *            评价人姓名
     * @param evalnum
     *            评价类型,1:好评,0:差评
     */
    @Override
    public void pushEvaluation(String targetPhoneNumber, String valuatorName, String evalnum, String goodsNo)
            throws Exception {
        logger.info("enter pushEvaluation of AppPushToDriverServiceImpl ");
        if (StringUtil.isEmpty(targetPhoneNumber)) {
            throw new Exception("被评价者手机号不可为空");
        }
        if (StringUtil.isEmpty(valuatorName)) {
            throw new Exception("评价者姓名不可为空");
        }
        if (StringUtil.isBlank(goodsNo)) {
            goodsNo = "000000000";
        }
        List<String> phoneNumbers = new ArrayList<String>();
        phoneNumbers.add(targetPhoneNumber);
        DataUtil.choosePhoneByOnLine(phoneNumbers);// 剔除不在线的用户
        logger.info("剔除不在线用户后:" + phoneNumbers.toString());
        DataUtil.choosePushSetOn(phoneNumbers, TermsCode.APP_PUSHINSTALL_TYPE_LIST.TOEVALREMIND_STATE);// 剔除关掉了推送设置的用户
        logger.info("剔除关掉了推送设置的用户后:" + phoneNumbers.toString());
        if (phoneNumbers == null || phoneNumbers.isEmpty()) {
            return;
        }
        String token = "";//appDeviceService.selectToken(targetPhoneNumber, AppVersionConstant.TYPE_ANDROID_CONSIGNER);
        int appType = AppVersionConstant.TYPE_ANDROID_CONSIGNER;
        if (StringUtil.isEmpty(token)) {
            token = "";//appDeviceService.selectToken(targetPhoneNumber, AppVersionConstant.TYPE_IOS_CONSIGNER);
            appType = AppVersionConstant.TYPE_IOS_CONSIGNER;
        }
        if (StringUtil.isEmpty(token)) {
            throw new Exception("被评价者手机号" + targetPhoneNumber + "没有找寻到对应的数据，无法开始推送服务");
        }
        if (appType == AppVersionConstant.TYPE_ANDROID_CONSIGNER) {
            AndroidPushCustomMessage custom = new AndroidPushCustomMessage();
            custom.setAppType(appType);
            custom.setType(AppPushConstant.OPERATION_TYPE_EVALUATION_2);
            String pushContent = "";
            if ("5".equals(evalnum)) {// 好评
                pushContent = valuatorName + "承运方给出" + evalnum + "星好评，订单尾号" + goodsNo.substring(goodsNo.length() - 6)
                        + "。";
            } else if ("0".equals(evalnum)) {// 差评
                pushContent = valuatorName + "承运方给出差评,1小时内可沟通修改，订单尾号" + goodsNo.substring(goodsNo.length() - 6) + "。";
            } else {// 都不是
                pushContent = valuatorName + "承运方给出" + evalnum + "星评价，订单尾号" + goodsNo.substring(goodsNo.length() - 6)
                        + "。";
            }
            custom.setContext(pushContent);
            // 承运人评价发货方，发货方收不到，看到这里把client 使用成了物流端的client,所以改成 发货方的client
            push2Android(AppPushConstant.OPERATION_TYPE_EVALUATION_2, PushConstant.DISPLAY_TYPE_MESSAGE,
                    PushConstant.TYPE_UNICAST, AppPushConstant.PUSH_EVALUATION_DRIVER_TITLE, pushContent, token,
                    consignerPushAndroidClient, custom);
        } else {
            IOSPushCustomMessage customIOS = new IOSPushCustomMessage();
            customIOS.setAppType(appType);
            customIOS.setType(AppPushConstant.OPERATION_TYPE_EVALUATION_2);
            String pushContent = "";
            if ("5".equals(evalnum)) {// 好评
                pushContent = valuatorName + "承运方给出" + evalnum + "星好评，订单尾号" + goodsNo.substring(goodsNo.length() - 6)
                        + "。";
            } else if ("0".equals(evalnum)) {// 差评
                pushContent = valuatorName + "承运方给出差评,1小时内可沟通修改，订单尾号" + goodsNo.substring(goodsNo.length() - 6) + "。";
            } else {// 都不是
                pushContent = valuatorName + "承运方给出" + evalnum + "星评价，订单尾号" + goodsNo.substring(goodsNo.length() - 6)
                        + "。";
            }
            customIOS.setContext(pushContent);
            push2IOS(AppPushConstant.OPERATION_TYPE_EVALUATION_2, PushConstant.TYPE_UNICAST,
                    AppPushConstant.PUSH_EVALUATION_DRIVER_TITLE, token, logisticsinfoPushIOSClient, customIOS);
        }
    }

    // 我要用车、我要发货接口，推送信息给同城司机接口
    // 返回成功推送数
    public int pushGoodToSameCity(GoodsVo goodsVo) throws Exception {
        logger.info("enter pushGoodToSameCity of AppPushToDriverServiceImpl ");
        int pushSuccessCount = 0;
        // 先查看附近30公里内是否有大于50条的货源,没有再查看60公里内,依次类推
        BoundsVo boundsVo = new BoundsVo();
        boundsVo.setLat(goodsVo.getStartLat());
        boundsVo.setLng(goodsVo.getStartLng());
        boundsVo.setAccountId(goodsVo.getAccountId());
        int pushCityScope = Integer.parseInt(PropertiesUtil.readValue(PropertiesUtil.PUSH_PATH,
                PropertiesUtil.PUSH_CITY_SCOPE));
        BoundsVo boundsvo = this.getsubLnglat(boundsVo, pushCityScope);

//        MebDriverQuery q = new MebDriverQuery();
//        // q.setBdLat(goodsVo.getStartLat());
//        // q.setBdLng(goodsVo.getStartLng());
//        // q.setDistance(30);
//        q.setSubLngfrom(boundsvo.getSubLngfrom());
//        q.setSubLngto(boundsvo.getSubLngto());
//        q.setSubLatfrom(boundsvo.getSubLatfrom());
//        q.setSubLatto(boundsvo.getSubLatto());

//        q.setMebAccId(goodsVo.getAccountId());// 发货人的账号id
//        q.setMebAccIdOfBlack(goodsVo.getAccountId()); // 排除此账号的黑名单关系
//        List<MebDriver> list = mebDriverIMapper.selectAccountByBDLngLat4SameCity(q);
        List<String> phoneNumbers = Lists.newArrayList();
        phoneNumbers.add("15101633389");
        phoneNumbers.add("18911840331");
//        Map<String, MebDriver> map = Maps.newHashMap();
//        for (MebDriver li : list) {
//            phoneNumbers.add(li.getAccount());
//            map.put(li.getAccount(), li);
//        }
//        DataUtil.choosePhoneByOnLine(phoneNumbers);// 剔除不在线的用户
        logger.info("剔除不在线用户后:" + phoneNumbers.toString());
        DataUtil.choosePushSetOn(phoneNumbers, TermsCode.APP_PUSHINSTALL_TYPE_LIST.GOODSREMIND_STATE);// 剔除关掉了推送设置的用户
        logger.info("剔除关掉了推送设置的用户后:" + phoneNumbers.toString());

//        for (String phoneNumbersObj : phoneNumbers) {
//            if (map.containsKey(phoneNumbersObj)) {
//                // 2.根据经纬度和订单的终点经纬度进行计算。
//                int distanceDriver = (int) MatchUtil.getDistance(goodsVo.getStartLng(), goodsVo.getStartLat(),
//                        map.get(phoneNumbersObj).getBdLng(), map.get(phoneNumbersObj).getBdLat());
//                // 将距离司机改为公里
//                double dis = (double) distanceDriver;
//                DecimalFormat format = new DecimalFormat("#0.0");
//                // appDayGoodspushVo.setDistance(format.format(d / 1000));
//                goodsVo.setDistanceDriver(format.format(dis / 1000));
//            }
//            List<String> aa = Lists.newArrayList();
//            aa.add(phoneNumbersObj);
//            if (aa.size() > 0) {
//                pushSuccessCount = pushGoodToDriver(goodsVo, aa);
//            }
//        }

        // if (phoneNumbers.size() > 0) {
        // pushSuccessCount = pushGoodToDriver(goodsVo, phoneNumbers);
        // }
        return pushSuccessCount;
    }

    /**
     * 获取周边i公里的最大最小经纬度
     * 
     * @param boundsVo
     * @param i
     *            公里
     * @return
     */
    public BoundsVo getsubLnglat(BoundsVo boundsVo, int i) {
        // System.out.println("进来时参数,lng:" + boundsVo.getLng() + ",lat:" +
        // boundsVo.getLat());
        if (i == 10) {
            return boundsVo;
        }
        if (boundsVo == null) {
            return new BoundsVo();
        }
        if (StringUtil.isBlank(boundsVo.getLng()) || boundsVo.getLng().indexOf(".") < 0
                || StringUtil.isBlank(boundsVo.getLat()) || boundsVo.getLat().indexOf(".") < 0) {
            return new BoundsVo();
        }
        int dif = 10000 * i;// i 公里
        int add = dif;
        BoundsVo boundsVo2 = new BoundsVo();
        boundsVo2.setAccountId(boundsVo.getAccountId());

        int n1 = 10;
        int n2 = 9;
        // do {
        // 不足位数后面补0
        if (boundsVo.getLng().length() < 10) {
            boundsVo.setLng(boundsVo.getLng() + String.format("%1$0" + (n1 - boundsVo.getLng().length()) + "d", 0));
        }
        if (boundsVo.getLat().length() < 9) {
            boundsVo.setLat(boundsVo.getLat() + String.format("%1$0" + (n2 - boundsVo.getLat().length()) + "d", 0));
        }
        // 转成long 方便运算
        long doublng = Long.parseLong(boundsVo.getLng().replace(".", ""));
        long doublat = Long.parseLong(boundsVo.getLat().replace(".", ""));
        // 计算
        boundsVo2.setSubLngfrom(String.valueOf(doublng - dif));
        boundsVo2.setSubLngto(String.valueOf(doublng + dif));

        boundsVo2.setSubLatfrom(String.valueOf(doublat - dif));
        boundsVo2.setSubLatto(String.valueOf(doublat + dif));
        dif += add;
        // 补"."
        StringBuffer bufflngfrom = new StringBuffer(boundsVo2.getSubLngfrom());
        StringBuffer bufflngto = new StringBuffer(boundsVo2.getSubLngto());
        StringBuffer bufflatfrom = new StringBuffer(boundsVo2.getSubLatfrom());
        StringBuffer bufflatto = new StringBuffer(boundsVo2.getSubLatto());

        boundsVo2.setSubLngfrom(bufflngfrom.insert(boundsVo.getLng().indexOf("."), ".").toString());
        boundsVo2.setSubLngto(bufflngto.insert(boundsVo.getLng().indexOf("."), ".").toString());
        boundsVo2.setSubLatfrom(bufflatfrom.insert(boundsVo.getLat().indexOf("."), ".").toString());
        boundsVo2.setSubLatto(bufflatto.insert(boundsVo.getLat().indexOf("."), ".").toString());
        boundsVo2.setLng(boundsVo.getLng());
        boundsVo2.setLat(boundsVo.getLat());
        // count = mebDriverIMapper.selectDriversCountBylnglat(boundsVo2);

        // } while (count < 20 && dif < 100 * 10000);
        // System.out.println("出去时参数count:" + count + ",lngfrom:" +
        // boundsVo2.getSubLngfrom() + ",lngto:"
        // + boundsVo2.getSubLngto() + ";latfrom:" + boundsVo2.getSubLatfrom() +
        // ",latto:"
        // + boundsVo2.getSubLatto());
        return boundsVo2;
    }

    // 我要用车、我要发货接口，推送信息给干线司机接口
    // 返回成功推送数
    public int pushGoodToDifferenceCity(GoodsVo goodsVo) throws Exception {
        logger.info("enter pushGoodToDifferenceCity of AppPushToDriverServiceImpl ");
        int pushSuccessCount = 0;
//        MebDriverQuery query = new MebDriverQuery();
//        query.setRunLineFromProviceCode(goodsVo.getStartProvice());
//        query.setRunLineFromCityCode(goodsVo.getStartCity());
//        query.setRunLineFromCountryCode(goodsVo.getStartCounty());
//        query.setRunLineToProviceCode(goodsVo.getEndProvice());
//        query.setRunLineToCityCode(goodsVo.getEndCity());
//        query.setRunLineToCountryCode(goodsVo.getEndCounty());
//        query.setMebAccId(goodsVo.getAccountId());// 发货人的账号id
//        List<String> phoneNumbers = mebDriverIMapper.selectAccountByLine(query);
//        DataUtil.choosePhoneByOnLine(phoneNumbers);// 剔除不在线的用户
//        logger.info("剔除不在线用户后:" + phoneNumbers.toString());
//        DataUtil.choosePushSetOn(phoneNumbers, TermsCode.APP_PUSHINSTALL_TYPE_LIST.GOODSREMIND_STATE);// 剔除关掉了推送设置的用户
//        logger.info("剔除关掉了推送设置的用户后:" + phoneNumbers.toString());
//        if (phoneNumbers.size() > 0) {
//            pushSuccessCount = pushGoodToDriver(goodsVo, phoneNumbers);
//        }
        return pushSuccessCount;

    }

    // 返回推送成功次数
    private int pushGoodToDriver(GoodsVo goodsVo, List<String> phoneNumbers) throws Exception {
        int pushSuccessCount = 0;
        List<String> androidTokenList = getAndroidTokens(phoneNumbers);
        List<String> iosTokenList = getIosTokens(phoneNumbers);
        if (androidTokenList.size() > 0) {
            pushFindDriverInfo2Android(goodsVo, androidTokenList);
            pushSuccessCount += androidTokenList.size();
        }
        if (iosTokenList.size() > 0) {
            pushFindDriverInfo2IOS(goodsVo, iosTokenList);
            pushSuccessCount += iosTokenList.size();
        }

        // 另外再将货源推送数据记录到当日货源推送表中
        if (phoneNumbers != null && !phoneNumbers.isEmpty()) {
            for (int i = 0; i < phoneNumbers.size(); i++) {
                if (StringUtil.isBlank(phoneNumbers.get(i))) {
                    continue;
                }
//                AppDayGoodspush appDayGoodspush = addDayGoodspush(goodsVo, phoneNumbers.get(i), i);
            }
        }
        return pushSuccessCount;

    }

    // 返回取消同城订单的成功推送个数
    public int pushCancelOrderBySameCity(GoodsVo goodsVo) throws Exception {
        logger.info("enter pushCancelOrderBySameCity of AppPushToDriverServiceImpl ");
        int pushSuccessCount = 0;
        List<String> phoneNumbers = Lists.newArrayList();
        phoneNumbers.add(goodsVo.getCarrierAccount());
        DataUtil.choosePhoneByOnLine(phoneNumbers);// 剔除不在线的用户
        logger.info("剔除不在线用户后:" + phoneNumbers.toString());
        DataUtil.choosePushSetOn(phoneNumbers, TermsCode.APP_PUSHINSTALL_TYPE_LIST.GOODSREMIND_STATE);// 剔除关掉了推送设置的用户
        logger.info("剔除关掉了推送设置的用户后:" + phoneNumbers.toString());
        if (phoneNumbers.size() > 0) {
            logger.info("开始进入推送pushCancelOrderToDriver");
            pushSuccessCount = pushCancelOrderToDriver(goodsVo, phoneNumbers);
        }
        return pushSuccessCount;

    }

    // 返回取消同城订单的成功推送个数
    public int pushCancelOrderToDriver(GoodsVo goodsVo, List<String> phoneNumbers) throws Exception {
        logger.info("come on pushCancelOrderToDriver function");
        logger.info("phoneNumbers:" + phoneNumbers);
        if (phoneNumbers != null) {
            for (String nums : phoneNumbers) {
                logger.info("nums:" + nums);
            }
        }

        int pushSuccessCount = 0;
        // List<String> androidTokenList = getAndroidTokens(phoneNumbers);
        // List<String> iosTokenList = getIosTokens(phoneNumbers);

//        List<AppDevice> appDeviceList = appDeviceService.selectEntitysByPhoneList(phoneNumbers);
//        if (appDeviceList != null && appDeviceList.size() > 0) {
//            pushCancelOrder(goodsVo, appDeviceList);
//            pushSuccessCount += appDeviceList.size();
//        }
        // if (androidTokenList.size() > 0) {
        // logger.info("androidTokenList size > 0");
        // pushCancelOrder2Android(goodsVo, androidTokenList);
        // pushSuccessCount += androidTokenList.size();
        // }
        // if (iosTokenList.size() > 0) {
        // logger.info("iosTokenList size > 0");
        // pushCancelOrder2IOS(goodsVo, iosTokenList);
        // pushSuccessCount += iosTokenList.size();
        // }

        return pushSuccessCount;

    }

    private void pushCancelOrder(GoodsVo goodsVo, List<AppDevice> appDeviceList) throws Exception {
        // 判断类型
        for (AppDevice appDe : appDeviceList) {
            logger.info("for pushCancelOrder list:" + appDe.getDeviceToken());

            if (ArrayUtil.contains(AppVersionConstant.ANDROID_TYPE, appDe.getAppType())) {
                // 安卓
                String pushText = MatchUtil.getSameCityPushConText(goodsVo);
                goodsVo.setConLabel(pushText);
                AndroidPushCustomMessage custom = new AndroidPushCustomMessage();
                // custom.setType(AppPushConstant.OPERATION_TYPE_CANCEL_ORDER_BY_SAME_CITY_TO_DRIVER);
                custom.setContext(pushText);
                custom.setGoodVo(goodsVo);

                if (AppVersionConstant.TYPE_ANDROID_ENTERPRISE == appDe.getAppType()) {
                    // 物流
                    custom.setAppType(AppVersionConstant.TYPE_ANDROID_ENTERPRISE);
                    custom.setType(AppPushConstant.OPERATION_TYPE_CANCEL_ORDER_TO_INFO);
                    push2Android(AppPushConstant.OPERATION_TYPE_CANCEL_ORDER_TO_INFO,
                            PushConstant.DISPLAY_TYPE_MESSAGE, PushConstant.TYPE_LISTCAST,
                            AppPushConstant.PUSH_CANCLE_ORDER_TITLE, pushText, appDe.getDeviceToken(),
                            logisticsinfoPushAndroidClient, custom);
                } else if (AppVersionConstant.TYPE_ANDROID_DRIVER == appDe.getAppType()) {
                    // 司机
                    custom.setAppType(AppVersionConstant.TYPE_ANDROID_DRIVER);
                    custom.setType(AppPushConstant.OPERATION_TYPE_CANCEL_ORDER_BY_SAME_CITY_TO_DRIVER);
                    push2Android(AppPushConstant.OPERATION_TYPE_CANCEL_ORDER_BY_SAME_CITY_TO_DRIVER,
                            PushConstant.DISPLAY_TYPE_MESSAGE, PushConstant.TYPE_LISTCAST,
                            AppPushConstant.PUSH_CANCLE_ORDER_TITLE, pushText, appDe.getDeviceToken(),
                            driverPushAndroidClient, custom);
                }

            } else if (ArrayUtil.contains(AppVersionConstant.IOS_TYPE, appDe.getAppType())) {
                String pushText = MatchUtil.getSameCityPushConText(goodsVo);
                goodsVo.setConLabel(pushText);
                IOSPushCustomMessage customIOS = new IOSPushCustomMessage();
                // customIOS.setType(AppPushConstant.OPERATION_TYPE_CANCEL_ORDER_BY_SAME_CITY_TO_DRIVER);
                customIOS.setContext(pushText);
                customIOS.setGoodVo(goodsVo);

                if (AppVersionConstant.TYPE_IOS_ENTERPRISE == appDe.getAppType()) {
                    // 物流
                    customIOS.setAppType(AppVersionConstant.TYPE_IOS_ENTERPRISE);
                    customIOS.setType(AppPushConstant.OPERATION_TYPE_CANCEL_ORDER_TO_INFO);
                    push2IOS(AppPushConstant.OPERATION_TYPE_CANCEL_ORDER_TO_INFO, PushConstant.TYPE_LISTCAST, pushText,
                            appDe.getDeviceToken(), logisticsinfoPushIOSClient, customIOS);
                } else if (AppVersionConstant.TYPE_IOS_DRIVER == appDe.getAppType()) {
                    // 司机
                    customIOS.setAppType(AppVersionConstant.TYPE_IOS_DRIVER);
                    customIOS.setType(AppPushConstant.OPERATION_TYPE_CANCEL_ORDER_BY_SAME_CITY_TO_DRIVER);
                    push2IOS(AppPushConstant.OPERATION_TYPE_CANCEL_ORDER_BY_SAME_CITY_TO_DRIVER,
                            PushConstant.TYPE_LISTCAST, pushText, appDe.getDeviceToken(), driverPushIOSClient,
                            customIOS);
                }

            }
        }
    }

    // 这里的方法把推送类型都写死了，只兼容推送给司机，不建议使用
    private void pushCancelOrder2IOS(GoodsVo goodsVo, List<String> iosTokenList) throws Exception {
        String pushText = MatchUtil.getSameCityPushConText(goodsVo);
        goodsVo.setConLabel(pushText);
        IOSPushCustomMessage customIOS = new IOSPushCustomMessage();
        customIOS.setType(AppPushConstant.OPERATION_TYPE_CANCEL_ORDER_BY_SAME_CITY_TO_DRIVER);
        customIOS.setContext(pushText);
        customIOS.setGoodVo(goodsVo);
        for (String tokenStr : iosTokenList) {
            push2IOS(AppPushConstant.OPERATION_TYPE_CANCEL_ORDER_BY_SAME_CITY_TO_DRIVER, PushConstant.TYPE_LISTCAST,
                    AppPushConstant.PUSH_CANCLE_ORDER_TITLE, tokenStr, driverPushIOSClient, customIOS);
        }
    }

    // 这里的方法把推送类型都写死了，只兼容推送给司机，不建议使用
    private void pushCancelOrder2Android(GoodsVo goodsVo, List<String> androidTokenList) throws Exception {
        logger.info("come pushCancelOrder2Android fun ###");
        String pushText = MatchUtil.getSameCityPushConText(goodsVo);
        goodsVo.setConLabel(pushText);
        AndroidPushCustomMessage custom = new AndroidPushCustomMessage();
        custom.setType(AppPushConstant.OPERATION_TYPE_CANCEL_ORDER_BY_SAME_CITY_TO_DRIVER);
        custom.setContext(pushText);
        custom.setGoodVo(goodsVo);
        for (String tokenStr : androidTokenList) {
            logger.info("for androidTokenList list:" + tokenStr);
            push2Android(AppPushConstant.OPERATION_TYPE_CANCEL_ORDER_BY_SAME_CITY_TO_DRIVER,
                    PushConstant.DISPLAY_TYPE_MESSAGE, PushConstant.TYPE_LISTCAST,
                    AppPushConstant.PUSH_CANCLE_ORDER_TITLE, pushText, tokenStr, driverPushAndroidClient, custom);
        }
    }

//    private AppDayGoodspush addDayGoodspush(GoodsVo goodsVo, String phoneNumber, int i) {
//        AppDayGoodspush appDayGoodspush = new AppDayGoodspush();
//        try {
//            appDayGoodspush.setAccountId(goodsVo.getAccountId());
//            appDayGoodspush.setGoodsId(goodsVo.getId());
//            appDayGoodspush.setGoodsNo(goodsVo.getGoodsNo());
//            appDayGoodspush.setGoodsRemark(goodsVo.getGoodsRemark());
//            appDayGoodspush.setReceiveAccount(phoneNumber);
//            appPushTaskMapper.insertAppDayGoodsPush(appDayGoodspush);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return appDayGoodspush;
//    }

    private void pushFindDriverInfo2IOS(GoodsVo goodsVo, List<String> iosTokenList) throws Exception {
        String pushText = MatchUtil.getSameCityPushText(goodsVo);
        IOSPushCustomMessage customIOS = new IOSPushCustomMessage();
        customIOS.setType(AppPushConstant.OPERATION_TYPE_GOOD_TO_DRIVER);
        customIOS.setContext(pushText);
        customIOS.setGoodVo(goodsVo);
        for (String tokenStr : iosTokenList) {
            push2IOS(AppPushConstant.OPERATION_TYPE_GOOD_TO_DRIVER, PushConstant.TYPE_LISTCAST, pushText, tokenStr,
                    driverPushIOSClient, customIOS);
        }
    }

    private void pushFindDriverInfo2Android(GoodsVo goodsVo, List<String> androidTokenList) throws Exception {
        String pushText = MatchUtil.getSameCityPushText(goodsVo);
        AndroidPushCustomMessage custom = new AndroidPushCustomMessage();
        custom.setType(AppPushConstant.OPERATION_TYPE_GOOD_TO_DRIVER);
        custom.setContext(pushText);
        custom.setGoodVo(goodsVo);
        for (String tokenStr : androidTokenList) {
            push2Android(AppPushConstant.OPERATION_TYPE_GOOD_TO_DRIVER, PushConstant.DISPLAY_TYPE_MESSAGE,
                    PushConstant.TYPE_LISTCAST, AppPushConstant.PUSH_FIND_DRIVER_INFO_TITLE, pushText, tokenStr,
                    driverPushAndroidClient, custom);
        }
    }

    private List<String> getIosTokens(List<String> phoneNumbers) {
        List<String> iosTokenList = new ArrayList<String>();
        StringBuilder tokenBuild = new StringBuilder();
        int tokenCount = 0;
        for (String phoneNumber : phoneNumbers) {
            // 根据手机号查询当前手机号类型，进行推送，因为可能是司机、可能是物流公司，不能写死成司机。
            // String token = appDeviceService.selectToken(phoneNumber,
            // AppVersionConstant.TYPE_IOS_DRIVER);

            String token = "";
//            MebAcc mebAcc = mebAccIMapper.selectOneEntityByAccunt(phoneNumber);
//            if (mebAcc != null && MebAccConstant.MEB_INFO.equals(mebAcc.getAccountType())) {
//                token = appDeviceService.selectToken(phoneNumber, AppVersionConstant.TYPE_IOS_ENTERPRISE);
//            } else if (mebAcc != null && MebAccConstant.MEB_DRIVER.equals(mebAcc.getAccountType())) {
//                token = appDeviceService.selectToken(phoneNumber, AppVersionConstant.TYPE_IOS_DRIVER);
//            }

            if (StringUtil.isNotEmpty(token)) {
                tokenBuild.append("," + token);
                tokenCount++;
            }
            if (tokenCount == 500) {
                iosTokenList.add(tokenBuild.toString().substring(1));
                tokenCount = 0;
            }
        }
        if (tokenBuild.length() > 1) {
            iosTokenList.add(tokenBuild.toString().substring(1));
        }
        return iosTokenList;
    }

    private List<String> getAndroidTokens(List<String> phoneNumbers) {
        StringBuilder tokenBuild = new StringBuilder();
        int tokenCount = 0;
        List<String> androidTokenList = new ArrayList<String>();
        for (String phoneNumber : phoneNumbers) {
            // 根据手机号查询当前手机号类型，进行推送，因为可能是司机、可能是物流公司，不能写死成司机。
            // String token = appDeviceService.selectToken(phoneNumber,
            // AppVersionConstant.TYPE_ANDROID_DRIVER);

            String token = "";
//            MebAcc mebAcc = mebAccIMapper.selectOneEntityByAccunt(phoneNumber);
//            if (mebAcc != null && MebAccConstant.MEB_INFO.equals(mebAcc.getAccountType())) {
//                token = appDeviceService.selectToken(phoneNumber, AppVersionConstant.TYPE_ANDROID_ENTERPRISE);
//            } else if (mebAcc != null && MebAccConstant.MEB_DRIVER.equals(mebAcc.getAccountType())) {
//                token = appDeviceService.selectToken(phoneNumber, AppVersionConstant.TYPE_ANDROID_DRIVER);
//            }

            if (StringUtil.isNotEmpty(token)) {
                tokenBuild.append("," + token);
                tokenCount++;
            }
            if (tokenCount == 500) {
                androidTokenList.add(tokenBuild.toString().substring(1));
                tokenCount = 0;
            }
        }
        if (tokenBuild.length() > 1) {
            androidTokenList.add(tokenBuild.toString().substring(1));
        }
        return androidTokenList;
    }

    // 审核信息推送消息
    @Override
    public void pushMsgByAccount(String phoneNumber, String pushTitle, String pushText, String accountType,
            AbstractVo abstractVo) throws Exception {
        logger.info("enter pushMsgByAccount of AppPushToDriverServiceImpl ");
        if (StringUtil.isBlank(phoneNumber)) {
            return;
        }
        List<String> phoneNumbers = new ArrayList<String>();
        phoneNumbers.add(phoneNumber);
        DataUtil.choosePhoneByOnLine(phoneNumbers);// 剔除不在线的用户
        logger.info("剔除不在线用户后:" + phoneNumbers.toString());
        if (phoneNumbers == null || phoneNumbers.isEmpty()) {
            return;
        }
        List<String> androidTokenList = getAndroidTokens(phoneNumbers);
        List<String> iosTokenList = getIosTokens(phoneNumbers);
        if (StringUtil.isBlank(pushTitle)) {
            pushTitle = AppPushConstant.PUSH_SYS_MSG_TITLE;
        }
        if (androidTokenList != null && androidTokenList.size() > 0) {
            AndroidPushCustomMessage custom = new AndroidPushCustomMessage();
            custom.setType(AppPushConstant.OPERATION_TYPE_UPDATE_MEB_DRIVER);
            custom.setContext(pushText);
            try {
                if (abstractVo != null) {
                    if (TermsCode.CLIENT_TYPE_LIST.CONSUGNOR.getValue().equals(accountType)) {
                        custom.setMebConsignerVo((MebConsignerVo) abstractVo);
                    } else if (TermsCode.CLIENT_TYPE_LIST.INFO.getValue().equals(accountType)) {
                        custom.setMebInfoVo((MebInfoVo) abstractVo);
                    } else if (TermsCode.CLIENT_TYPE_LIST.DRIVER.getValue().equals(accountType)) {
                        custom.setMebDriverVo((MebDriverVo) abstractVo);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            push2Android(AppPushConstant.OPERATION_TYPE_UPDATE_MEB_DRIVER, PushConstant.DISPLAY_TYPE_MESSAGE,
                    PushConstant.TYPE_UNICAST, pushTitle, pushText, androidTokenList.get(0), driverPushAndroidClient,
                    custom);
        }

        if (iosTokenList != null && iosTokenList.size() > 0) {
            IOSPushCustomMessage customIOS = new IOSPushCustomMessage();
            customIOS.setType(AppPushConstant.OPERATION_TYPE_UPDATE_MEB_DRIVER);
            customIOS.setContext(pushText);
            try {
                if (abstractVo != null) {
                    if (TermsCode.CLIENT_TYPE_LIST.CONSUGNOR.getValue().equals(accountType)) {
                        customIOS.setMebConsignerVo((MebConsignerVo) abstractVo);
                    } else if (TermsCode.CLIENT_TYPE_LIST.INFO.getValue().equals(accountType)) {
                        customIOS.setMebInfoVo((MebInfoVo) abstractVo);
                    } else if (TermsCode.CLIENT_TYPE_LIST.DRIVER.getValue().equals(accountType)) {
                        customIOS.setMebDriverVo((MebDriverVo) abstractVo);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            push2IOS(AppPushConstant.OPERATION_TYPE_UPDATE_MEB_DRIVER, PushConstant.TYPE_UNICAST, pushText,
                    iosTokenList.get(0), driverPushIOSClient, customIOS);
        }

    }

    // 推送-单播
    @Override
    public void pushSysMsgByAccount(int operationType, String phoneNumber, String pushTitle, String pushText)
            throws Exception {
        logger.info("enter pushSysMsgByAccount of AppPushToDriverServiceImpl ");
        if (StringUtil.isBlank(phoneNumber)) {
            return;
        }
        List<String> phoneNumbers = new ArrayList<String>();
        phoneNumbers.add(phoneNumber);

        List<String> androidTokenList = getAndroidTokens(phoneNumbers);
        List<String> iosTokenList = getIosTokens(phoneNumbers);
        if (StringUtil.isBlank(pushTitle)) {
            pushTitle = AppPushConstant.PUSH_SYS_MSG_TITLE;
        }
        if (androidTokenList != null && androidTokenList.size() > 0) {
            AndroidPushCustomMessage custom = new AndroidPushCustomMessage();
            custom.setType(AppPushConstant.OPERATION_TYPE_TO_CONFIRM_GET_GOODS);
            custom.setContext(pushText);
            push2Android(operationType, PushConstant.DISPLAY_TYPE_MESSAGE, PushConstant.TYPE_UNICAST, pushTitle,
                    pushText, androidTokenList.get(0), driverPushAndroidClient, custom);
        }

        if (iosTokenList != null && iosTokenList.size() > 0) {
            IOSPushCustomMessage customIOS = new IOSPushCustomMessage();
            customIOS.setType(AppPushConstant.OPERATION_TYPE_TO_CONFIRM_GET_GOODS);
            customIOS.setContext(pushText);
            push2IOS(operationType, PushConstant.TYPE_UNICAST, pushText, iosTokenList.get(0), driverPushIOSClient,
                    customIOS);
        }

    }

    // 系统消息-所有设备
    @Override
    public void pushSysMsgAll(String title, String pushText) throws Exception {

        pushSysMsgAll(AppPushConstant.OPERATION_TYPE_SYS_MSG_ALL, title, pushText);
    }

    // 系统消息-所有设备
    @Override
    public void pushSysMsgAll(int operationType, String title, String pushText) throws Exception {
        logger.info("enter pushSysMsgAll of AppPushToDriverServiceImpl ");
        if (StringUtil.isBlank(title) || StringUtil.isBlank(pushText)) {
            return;
        }
        AndroidPushCustomMessage custom = new AndroidPushCustomMessage();
        custom.setType(operationType);
        custom.setContext(pushText);
        push2Android(operationType, PushConstant.DISPLAY_TYPE_MESSAGE, PushConstant.TYPE_BROADCAST, title, pushText,
                null, driverPushAndroidClient, custom);
        IOSPushCustomMessage customIOS = new IOSPushCustomMessage();
        customIOS.setType(operationType);
        push2IOS(operationType, PushConstant.TYPE_BROADCAST, pushText, null, driverPushIOSClient, customIOS);
    }

    // 帮扶信息-给所有符合周边的司机推送
    @Override
    public void pushHelp(HelpInfo helpInfo, BoundsVo respBoundsVo) throws Exception {
        logger.info("enter pushHelp of AppPushToDriverServiceImpl ");
        if (helpInfo == null) {
            return;
        }
        if (helpInfo.getMebacc() == null) {
            throw new Exception("发布帮扶用户信息获取失败");
        }

//        MebDriverQuery q = new MebDriverQuery();
//        q.setSubLngfrom(respBoundsVo.getSubLngfrom());
//        q.setSubLngto(respBoundsVo.getSubLngto());
//        q.setSubLatfrom(respBoundsVo.getSubLatfrom());
//        q.setSubLatto(respBoundsVo.getSubLatto());
//
//        q.setMebAccId(helpInfo.getMebId());// 发货人的账号id
        List<String> phoneNumbers = null;//mebDriverIMapper.selectBoundsDriverByBDLngLat(q);
        phoneNumbers.add("15101633389");
        phoneNumbers.add("18911840331");
        
        DataUtil.choosePhoneByOnLine(phoneNumbers);// 剔除不在线的用户
        logger.info("剔除不在线用户后:" + phoneNumbers.toString());
        
        if (phoneNumbers.size() > 0) {
            StringBuffer pushText = new StringBuffer();
            pushText.append(helpInfo.getMebacc().getAccount()).append(",").append(helpInfo.getHTypeLabel()).append(",")
                    .append(helpInfo.gethContext());
            List<String> androidTokenList = getAndroidTokens(phoneNumbers);
            List<String> iosTokenList = getIosTokens(phoneNumbers);

            AndroidPushCustomMessage custom = new AndroidPushCustomMessage();
            custom.setType(AppPushConstant.OPERATION_TYPE_HELP);
            custom.setContext(pushText.toString());
            for (String tokenStr : androidTokenList) {
                push2Android(AppPushConstant.OPERATION_TYPE_HELP, PushConstant.DISPLAY_TYPE_MESSAGE,
                        PushConstant.TYPE_LISTCAST, AppPushConstant.PUSH_HELP_TITLE, pushText.toString(), tokenStr,
                        driverPushAndroidClient, custom);
            }
            IOSPushCustomMessage customIOS = new IOSPushCustomMessage();
            customIOS.setType(AppPushConstant.OPERATION_TYPE_HELP);
            customIOS.setContext(pushText.toString());
            for (String tokenStr : iosTokenList) {
                push2IOS(AppPushConstant.OPERATION_TYPE_HELP, PushConstant.TYPE_LISTCAST,
                        AppPushConstant.PUSH_HELP_TITLE, tokenStr, driverPushIOSClient, customIOS);
            }

        }
    }

    // 推送测试-所有设备(列播)
    @Override
    public void pushTest(int operationType, String title, String context) {
//        List<MebAcc> mebAccList = mebAccIMapper.selectAllEntity();
        
        List<String> phoneNumbers = new ArrayList<String>();
//        for (MebAcc mebAcc : mebAccList) {
//            phoneNumbers.add(mebAcc.getAccount());
//        }
        phoneNumbers.add("15101633389");
        phoneNumbers.add("18911840331");
        // DataUtil.choosePhoneByOnLine(phoneNumbers);// 剔除不在线的用户
        List<String> androidTokenList = getAndroidTokens(phoneNumbers);
        List<String> iosTokenList = getIosTokens(phoneNumbers);
        try {
            AndroidPushCustomMessage custom = new AndroidPushCustomMessage();
            custom.setType(operationType);
            custom.setContext(context);
            for (String tokenStr : androidTokenList) {
                push2Android(operationType, PushConstant.DISPLAY_TYPE_MESSAGE, PushConstant.TYPE_LISTCAST, title,
                        context, tokenStr, driverPushAndroidClient, custom);
            }
            IOSPushCustomMessage customIOS = new IOSPushCustomMessage();
            customIOS.setType(operationType);
            customIOS.setContext(context);
            for (String tokenStr : iosTokenList) {
                push2IOS(operationType, PushConstant.TYPE_LISTCAST, context, tokenStr, driverPushIOSClient, customIOS);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        String s = "116.23";
        System.out.println(s.indexOf("."));
    }

}
